package com.six.backend.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: skyler
 * @Date: 2021/11/17 18:58
 */
public class getIpUtil {
    public static String getIpAddr(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        String str = "unknown";
        if (ip == null || ip.length() == 0 || str.equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || str.equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || str.equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}
